package com.dji.compose_learning.ui.view

import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun ScrollViewPage() {
    Surface(modifier = Modifier.fillMaxSize()) {
        Box(contentAlignment = Alignment.Center) {
//            ScrollList()
            ScrollListSmooth()
        }
    }
}

//sample 1
@Composable
fun ScrollList() {
    Column(modifier = Modifier
        .background(MaterialTheme.colorScheme.primary)
        .size(200.dp)
        .verticalScroll(
            rememberScrollState())) {
        repeat(100) {
            Text(text = "this is $it", color = MaterialTheme.colorScheme.onPrimary)
        }
    }
}

//sample 2
@Composable
fun ScrollListSmooth() {
    val state = rememberScrollState()
    LaunchedEffect(Unit) {
        state.animateScrollTo(value = 800, animationSpec = tween(durationMillis = 500))
    }

    Column(modifier = Modifier
        .background(MaterialTheme.colorScheme.primary)
        .size(200.dp)
        .verticalScroll(state)) {
        repeat(100) {
            Text(text = "this is $it", color = MaterialTheme.colorScheme.onPrimary)
        }
    }
}